package com.hyq.learn.security.cipher;

import com.hyq.learn.security.util.DESUtils;
import org.apache.commons.codec.binary.Base64;

/**
 * @author : heyuqin
 * @since : 2024/03/05 17:39
 */
public class DESCipherAlgorithm implements CipherAlgorithm{

    @Override
    public byte[] encryption(byte[] data, CipherKey key) throws Exception {
        byte[] keyBytes = DESUtils.getKeyBytes(Base64.decodeBase64(key.getKey()));
        return DESUtils.encrypt(data, keyBytes);
    }

    @Override
    public byte[] decryption(byte[] data, CipherKey key) throws Exception {
        byte[] keyBytes = DESUtils.getKeyBytes(Base64.decodeBase64(key.getKey()));
        return DESUtils.decrypt(data, keyBytes);
    }
}
